package com.copymd;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class ChuliHTMLXuhao {

    @Test
    public void excute() {
        String path = "E:\\BaiduNetdiskDownload\\DeepSeek+SpringAI大模型应用开发\\配套资料\\笔记";
        File dirs = new File(path);
        for (String file : dirs.list()) {
            String oldFile = path + "\\" + file;
            String newFile = path + "\\0000-" + file;
            String oldFileTxt = FileUtil.readString(oldFile, "UTF-8");
            String replace = oldFileTxt.replace("!function(e){\"use strict\";function t(){\"complete\"===document.readyState?n():e.addEventListener(\"DOMContentLoaded\",n)}function n(){try{var e=document.querySelectorAll(\"code.hljs\");for(var t in e)e.hasOwnProperty(t)&&r(e[t])}catch(n){console.error(\"LineNumbers error: \",n)}}function r(e){if(\"object\"==typeof e){var t=e.parentNode,n=o(t.textContent);if(n>1){for(var r=\"\",c=0;n>c;c++)r+=c+1+\"\\n\";var l=document.createElement(\"code\");l.className=\"hljs hljs-line-numbers\",l.style[\"float\"]=\"left\",l.textContent=r,t.insertBefore(l,e)}}}function o(e){if(0===e.length)return 0;var t=/\\r\\n|\\r|\\n/g,n=e.match(t);return n=n?n.length:0,e[e.length-1].match(t)||(n+=1),n}\"undefined\"==typeof e.hljs?console.error(\"highlight.js not detected!\"):(e.hljs.initLineNumbersOnLoad=t,e.hljs.lineNumbersBlock=r)}(window);", "");
            FileUtil.writeString(replace, newFile, "UTF-8");
        }
    }

    public void copyeFile(String oldFile, String newFile) {
        try {
            FileInputStream inputStream = new FileInputStream(new File(oldFile));
            FileOutputStream outputStream = new FileOutputStream(new File(newFile));
            IoUtil.copy(inputStream, outputStream);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

}
